using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Microsoft.CommerceServer.SecureSite
{
	public class MarketingWebService : Microsoft.CommerceServer.SecureSite.Wizard
	{
		private System.Windows.Forms.Panel pnlMarketing;
		private System.Windows.Forms.DataGrid dtGrdRoles;
		private System.Windows.Forms.Label lblRoleInstructions;
		private System.ComponentModel.IContainer components = null;

		public MarketingWebService()
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// btnNext
			// 
			this.btnNext.Name = "btnNext";
			// 
			// btnPrevious
			// 
			this.btnPrevious.Name = "btnPrevious";
			// 
			// MarketingWebService
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(552, 374);
			this.Name = "MarketingWebService";
			this.Load += new System.EventHandler(this.MarketingWebService_Load);
			this.Activated += new System.EventHandler(this.MarketingWebService_Activated);

		}
		#endregion

		protected override void btnPrevious_Click(object sender, System.EventArgs e)
		{
			CommerceSecurityInfo.MoveToForm("CatalogWebService");
			base.Visible = false;
		}

		protected override void btnNext_Click(object sender, System.EventArgs e)
		{
			if (base.IsValid)
			{
                CommerceSecurityInfo.MoveToForm("OrdersWebService");
				base.Visible = false;
			}
		}

		private void MarketingWebService_Load(object sender, System.EventArgs e)
		{
			this.pnlMarketing = new System.Windows.Forms.Panel();
			this.dtGrdRoles = new System.Windows.Forms.DataGrid();
			this.lblRoleInstructions = new System.Windows.Forms.Label();
			this.pnlMarketing.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dtGrdRoles)).BeginInit();
			this.SuspendLayout();
			// 
			// btnNext
			// 
			this.btnNext.Name = "btnNext";
			// 
			// btnPrevious
			// 
			this.btnPrevious.Name = "btnPrevious";
			// 
			// pnlMarketing
			// 
			this.pnlMarketing.Controls.Add(this.dtGrdRoles);
			this.pnlMarketing.Controls.Add(this.lblRoleInstructions);
			this.pnlMarketing.Dock = System.Windows.Forms.DockStyle.Fill;
			this.pnlMarketing.Location = new System.Drawing.Point(0, 72);
			this.pnlMarketing.Name = "pnlMarketing";
			this.pnlMarketing.Size = new System.Drawing.Size(552, 262);
			this.pnlMarketing.TabIndex = 4;
			// 
			// dtGrdRoles
			// 
			this.dtGrdRoles.DataMember = "";
			this.dtGrdRoles.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dtGrdRoles.Location = new System.Drawing.Point(32, 72);
			this.dtGrdRoles.Name = "dtGrdRoles";
			this.dtGrdRoles.Size = new System.Drawing.Size(480, 176);
			this.dtGrdRoles.TabIndex = 1;
			// 
			// lblRoleInstructions
			// 
			this.lblRoleInstructions.Location = new System.Drawing.Point(40, 16);
			this.lblRoleInstructions.Name = "lblRoleInstructions";
			this.lblRoleInstructions.Size = new System.Drawing.Size(464, 48);
			this.lblRoleInstructions.TabIndex = 0;
			this.lblRoleInstructions.Text = "label1";
			// 
			// MarketingWebService
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(552, 374);
			this.Controls.Add(this.pnlMarketing);
			this.Name = "MarketingWebService";
			this.Controls.SetChildIndex(this.pnlMarketing, 0);
			this.pnlMarketing.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dtGrdRoles)).EndInit();
			this.ResumeLayout(false);

			CommerceSecurityInfo.Log("FORM: Marketing Web Service form loaded");
			base.Title = "Marketing WebSerivce Roles";
			this.lblRoleInstructions.Text = "Enter user name to access Marketing WebService.";
		
			loadCatalogRoles();
		}

		private void loadCatalogRoles()
		{
			CommerceSecurityInfo.Mktgwebsvr = new CSWebService(WebServiceType.marketingWebService);

			try
			{
				CommerceSecurityInfo.SetAzManDataGrid(CommerceSecurityInfo.Mktgwebsvr, dtGrdRoles, this.BindingContext);
			}
			catch(Exception ex)
			{
				CommerceSecurityInfo.Log("Error: "+ex.Message);
				this.lblRoleInstructions.Text = "No Marketing WebService to set roles. Click the Next button To Continue.";
			}
		}

		private void MarketingWebService_Activated(object sender, System.EventArgs e)
		{
			if(CommerceSecurityInfo.IsDirty)
			{
				this.MarketingWebService_Load(sender, e);
			}
		}
	}
}

